/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.page.menu.contact;

import com.sun.lwuit.ButtonGroup;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.RadioButton;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import edu.mobbuzz.bean.Contact;
import edu.mobbuzz.facade.ContactFacade;
import edu.mobbuzz.page.menu.Menu;
import edu.mobbuzz.util.string.MenuString;

/**
 *
 * @author irw
 */
public class ContactDetail extends Menu{
    private Form contactForm;
    private Container contactPanel;
    private Label menuTitle;
    private Label nameLbl;
    private Label idLbl;
    private Label detailNameLbl;
    private Label detailIdLbl;
    private Label sexLbl;
    private ButtonGroup sexGroup;
    private RadioButton maleRadio;
    private RadioButton femaleRadio;    
    private Contact contact;
    
    public ContactDetail(){
        contactForm = new Form();
        contactPanel = new Container();
        menuTitle = new Label(getMenuTitle());
        
        nameLbl = new Label();
        idLbl = new Label();
        sexLbl = new Label();
        
        detailNameLbl = new Label();
        detailIdLbl = new Label();
        
        sexGroup = new ButtonGroup();
        maleRadio = new RadioButton("Male");
        femaleRadio = new RadioButton("Female");
    }
    
    public void showPage(){
        System.out.println("Sex" +getContact().getSex());
        sexGroup.add(maleRadio);
        sexGroup.add(femaleRadio);
        
        menuTitle.setAlignment(Component.CENTER);
        menuTitle.getStyle().setMargin(5, 0, 5, 0);
        menuTitle.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        menuTitle.getStyle().setBgTransparency(0);  
        
        nameLbl.setText("Name : ");
        nameLbl.getStyle().setMargin(5, 0, 10, 2);
        nameLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        nameLbl.getStyle().setBgTransparency(0);  
        
        detailNameLbl.setText(getContact().getName());
        detailNameLbl.getStyle().setMargin(0, 0, 10, 2);
        detailNameLbl.getStyle().setBgTransparency(0); 
        
        idLbl.setText("Mobbuzz ID : ");
        idLbl.getStyle().setMargin(5, 0, 10, 2);
        idLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        idLbl.getStyle().setBgTransparency(0);  
        
        detailIdLbl.setText(getContact().getId());
        detailIdLbl.getStyle().setMargin(0, 0, 10, 2);
        detailIdLbl.getStyle().setBgTransparency(0);
        
        sexLbl.setText("Sex : ");      
        sexLbl.getStyle().setMargin(5, 0, 10, 2);
        sexLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        sexLbl.getStyle().setBgTransparency(0);
        
        if(contact.getSex()==0){
            maleRadio.setSelected(true);
        }else{            
            femaleRadio.setSelected(true);
        }
        
        maleRadio.setEnabled(false);
        maleRadio.getStyle().setMargin(2, 0, 10, 0);
        maleRadio.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
        maleRadio.getStyle().setFgColor(0x49BBF9);
        maleRadio.getStyle().setFgSelectionColor(0x49BBF9);
        
        
        femaleRadio.setEnabled(false);
        femaleRadio.getStyle().setMargin(2, 0, 10, 0);
        femaleRadio.getStyle().setFgColor(0xF59FBC);
        femaleRadio.getStyle().setFgSelectionColor(0xF59FBC);
        femaleRadio.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
        
            
        contactPanel.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        contactPanel.addComponent(menuTitle);
        contactPanel.addComponent(nameLbl);
        contactPanel.addComponent(detailNameLbl);
        contactPanel.addComponent(idLbl);
        contactPanel.addComponent(detailIdLbl);
        contactPanel.addComponent(sexLbl);
        contactPanel.addComponent(maleRadio);
        contactPanel.addComponent(femaleRadio);
        
        contactForm.setLayout(new BorderLayout()); 
        contactForm.addComponent(BorderLayout.CENTER, contactPanel); 
        contactForm.addCommand(new Command("Back") {
            public void actionPerformed(ActionEvent evt) {
                backToContactPage();
            }
        });
        contactForm.setCommandListener(getActionlistener());
        contactForm.show();
    }
        
    public void backToContactPage(){
        ContactPage contactPage = new ContactPage();
        contactPage.setExitCmd(getExitCmd());
        contactPage.setActionlistener(getActionlistener());
        contactPage.showPage();
    }
    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public String getMenuTitle() {
        return MenuString.DETAIL_CONTACT;
    }
}
